// pages/SystemNotification/index.js

const app = getApp()
import {
  httpRequest,

} from '../../utils/http'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentData: 0,
    open:false,
    system: [],
    member: [],
    num:0,
    type:1,
    copyPN:'',
    canuse:[],
    unuse:[],
    shuju:[
      {
        num:0,
        time:1,
        money:5
      },{
        num:0,
        time:2,
        money:10
      },{
        num:0,
        time:3,
        money:15
      },{
        num:0,
        time:4,
        money:20
      },{
        num:0,
        time:5,
        money:25
      },{
        num:0,
        time:6,
        money:30
      },{
        num:0,
        time:7,
        money:35
      },{
        num:0,
        time:8,
        money:40
      },{
        num:0,
        time:12,
        money:60
      },{
        num:0,
        time:24,
        money:240
      }
    ],
    parkingList:[],
    parkinName:''
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   
  },
  onShow(){
    let that = this
    this.getNotice()
    wx.request({
      url: app.globalData.basicUrl+'system/parking/findAll',
      success: function (res) {
        that.setData({
          parkingList:res.data.data,
          parkinName:res.data.data[0].parkingName
        })
      }
    })
    this.getMyVoucher()
  },
  pickerOpen(){
    this.setData({
      open:true
    })
  },
  closePicker(){
    this.setData({
      open:false
    })
  },
  bindPickerChange(e){
    let index = e.detail.value[0]
    let parking = this.data.parkingList
    this.setData({
      copyPN:parking[index].parkingName
    })
  },
  search(){
    this.setData({
      parkinName:this.data.copyPN,
      open:false
    })
    
  },
  getMyVoucher(){
    let that = this
    httpRequest("/voucher/list","GET",{}).then(res=>{
      if(res.code == 200){
        let list = res.data.data
        let canuse = [];
        let unuse = []
        list.forEach((item)=>{
          console.log(item)
        if(item.voucherTypeId == 1){
            canuse.push(item)
        }else{
          unuse.push(item)
        }
        that.setData({
          canuse,
          unuse
        })
      })
      }
      
      
    })
  },
  getNotice(){
    console.log(this.options.currentDate)
    this.setData({
      currentData:this.options.currentDate
    })
  },
  buy(e){
    let shuju = this.data.shuju
    let index = e.currentTarget.dataset.index
    shuju[index].num+=1
    this.setData({
      shuju
    })
    this.getMoney(index)
  },
  jiaNum(e){
    let shuju = this.data.shuju
    let index = e.currentTarget.dataset.index
    shuju[index].num+=1
    this.setData({
      shuju
    })
    this.getMoney(index)
  },
  getMoney(){
    let shuju = this.data.shuju
    let num =0
    for(let i=0;i<shuju.length;i++){
      num += shuju[i].num*shuju[i].money;
    }
    this.setData({
      num
    })
  },
  jianNum(e){
    let shuju = this.data.shuju
    let index = e.currentTarget.dataset.index
    shuju[index].num-=1
    this.setData({
      shuju
    })
    this.getMoney(index)
  },
  toSettlement(){
    
    let shuju = JSON.stringify(this.data.shuju)
    wx.navigateTo({
      url: '/pages/settlement/index?shuju='+shuju,
    })
  },
  changeType(e){
    let that = this
   
    that.setData({
      type:e.currentTarget.dataset.index
    })
  },
  //获取当前滑块的index
  bindchange: function (e) {
    const that = this;
    that.setData({
      currentData: e.detail.current
    })
    console.log(that.data.currentData)
  },
  //点击切换，滑块index赋值
  checkCurrent: function (e) {
    const that = this;

    if (that.data.currentData === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentData: e.target.dataset.current
      })
    }
  },
})